///
///Author: YYF
///Date: 2020-12-19 15:29:56
///Description:
///

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import 'router_handler.dart';

class AppRoutes {
  static String root = '/';
  //路由静态化
  static FluroRouter router;

  /// 查看大图
  static String photoViewGalleryScreenPage = '/photoViewGalleryScreenPage';

  static void configureRotes(FluroRouter router) {
    router.notFoundHandler = Handler(
      handlerFunc: (context, parameters) {
        print('找不到对应路由页面');
      },
    );

    /// 查看大图
    // router.define(photoViewGalleryScreenPage,
    //     handler: photoViewGalleryScreenPageHandler);
  }

  // 对参数进行encode，解决参数中有特殊字符，影响fluro路由匹配
  static Future navigateTo(BuildContext context, String path,
      {Map<String, dynamic> params,
      TransitionType transition = TransitionType.native,
      bool replace = false,
      Function callBack}) {
    String query = "";
    if (params != null) {
      int index = 0;
      for (var key in params.keys) {
        var value = Uri.encodeComponent(params[key].toString());
        if (index == 0) {
          query = "?";
        } else {
          query = query + "\&";
        }
        query += "$key=$value";
        index++;
      }
    }
    debugPrint('我是navigateTo传递的参数：$query');
    path = path + query;
    return router.navigateTo(context, path,
        transition: transition, replace: replace);
  }
}
